﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml.Serialization;

namespace Tetris
{
    /// <summary>
    /// Used to Serialize/Deserialize the game
    /// </summary>
    static class Serialization
    {
        /// <summary>
        /// Save the current game object in a xml file named game.xml
        /// </summary>
        /// <param name="game">Current game</param>
        public static void Serialize(Game game)
        {
            XmlSerializer xs = new XmlSerializer(typeof(Game));
            using (StreamWriter wr = new StreamWriter("game.xml"))
            {
                xs.Serialize(wr, game);
            }
        }

        /// <summary>
        /// Get all information saved in game.xml and return a object game
        /// </summary>
        /// <returns></returns>
        public static Game Deserialize()
        {
            XmlSerializer xs = new XmlSerializer(typeof(Game));
            using (StreamReader rd = new StreamReader("game.xml"))
            {
                return xs.Deserialize(rd) as Game;
            }
        }
    }
}
